package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        /*
        查询1年级1班一共有多少人
         */
        try (Connection connection=DBUtil.getConnection()){
           Statement state= connection.createStatement();
           String sql="SELECT COUNT(*) count "+
                      "FROM class c " +
                      "JOIN student s ON s.class_id=c.id "+
                      "WHERE c.name='1年级1班'";
           ResultSet rs=state.executeQuery(sql);
           if (rs.next()){
               int count=rs.getInt("count");
               System.out.println("1年级1班共有"+count+"人");
           }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
